<?php

/*
 * these two lines MUST be first in all php files that are accessible through
 * the internet as they initialize security related stuff.
 */
define("DS", DIRECTORY_SEPARATOR);
include_once '..' . DS . '..' . DS . 'system' . DS . 'initialize.php';

define('DEFAULT_INDEX', 'index.html');

/*
 * don't worry, all GET VARS are clean, they can only contain letters, numbers
 * a dash, a dot, slashes and backslashes and the & and ? character.
 */
$options = array(
    'file' => (empty($_GET['file'])) ? DEFAULT_INDEX : $_GET['file'],
    'root' => '..' . DS . 'assets' . DS . 'Tmpl',
    'folder' => 'default',
);
$type = empty($_GET['type']) ? "html" : $_GET['type'];
switch ($type) {
    default:
    case 'htm' :
    case 'html' :
        /*
         * these will be pulled from database, just testing for now.
         * This will insert a title (filename) and a static menu in every page
         */
        $options['template']['data'] = array(
            '{##page_title##}' => $options['file'],
            '{##menu_content##}' => '
                <ul>
                    <li><a href="index.html">Home</a></li>
                    <li><a href="about.html">About Us</a></li>
                </ul>
            ',
        );
        header('Content-type: text/html; charset=utf-8');
        $html = new Tmpl($options);
        $html->get_targets();
        $html->replace_targets($options['template']['data']);
        $html->strip_targets();
        $html->tidy_up();

        $output = $html;
        break;
    case 'css' :
        header('Content-type: text/css');
        $css = new Css($options);
        $css->add_browser_prefixes();

        $output = $css;
        break;
    case 'js' :
        header('Content-type: application/javascript');
        $js = new File($options);
        $output = $js;
        break;
    case 'gif' :
        header('Content-Type: image/gif');
        $gif = new File($options);

        $output = $gif;
        break;
    case 'jpg' :
        header('Content-Type: image/jpeg');
        $jpg = new File($options);
        $output = $jpg;
        break;
    case 'png' :
        header('Content-Type: image/png');
        $png = new File($options);
        $output = $png;
        break;
}

// send your stuff to users screen ;)
echo $output;
